package com.kingdee.pda.util;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.kingdee.pda.R;

/**
 * ToastUtils
 */
public class ToastUtils {

    public static void showLongOnDeepBg(Context context, String message) {
        show(context, message, Toast.LENGTH_LONG, true);
    }

    public static void showLong(Context context, String message) {
        show(context, message, Toast.LENGTH_LONG);
    }

    public static void showShortOnDeepBg(Context context, String message) {
        show(context, message, Toast.LENGTH_SHORT, true);
    }

    public static void showShort(Context context, String message) {
        show(context, message, Toast.LENGTH_SHORT);
    }

    public static void showLong(Context context, int textId) {
        show(context, textId, Toast.LENGTH_LONG);
    }

    public static void showShort(Context context, int textId) {
        show(context, textId, Toast.LENGTH_SHORT);
    }


    public static void show(Context context, String text, int duration) {
        show(context, text, duration, false);
    }

    public static void show(Context context, String text, int duration, boolean isShowOnDeepBg) {
        if (context == null) {
            return;
        }
        Toast toast = Toast.makeText(context, text, duration);
        View view = LayoutInflater.from(context).inflate(R.layout.layout_toast, null);
        TextView tv_message = view.findViewById(R.id.tv_message);
        if (isShowOnDeepBg) {
            view.setBackgroundResource(R.drawable.shape_toast_bg);
            tv_message.setTextColor(ColorUtils.getColor(context, R.color.color_e41f2b));
        }
        tv_message.setText(text);
        toast.setView(view);
        toast.setGravity(Gravity.CENTER_HORIZONTAL, 0, -260);
        toast.show();
    }

    public static void show(Context context, int textId, int duration) {
        if (context == null) {
            return;
        }
        show(context, context.getString(textId), duration);
    }


    public static void showToast(Context context, View layout) {
        Toast toast = new Toast(context);
        toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
        toast.setDuration(Toast.LENGTH_SHORT);
        toast.setView(layout);
        toast.show();
    }

    public static void showToastBottom(Context context, View layout, int marginBottom) {
        Toast toast = new Toast(context);
        toast.setGravity(Gravity.BOTTOM, 0, marginBottom);
        toast.setDuration(Toast.LENGTH_SHORT);
        toast.setView(layout);
        toast.show();
    }
}
